<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<div>
		<form action="${ctx }/edocEntry/update?pageNum=${pageNum}&selectVal=${selectVal}" method="post"> 
			
			<input type="hidden" name="id" value="${edoc.id }">
			<input type="hidden" name="categoryId" value="${edoc.categoryId }">
			
			<table>
				<thead>
					<tr>
						<td colspan="2"> <h1>修改电子文档</h1></td>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td>文档编号<span style="color: red">(*)</span></td>
						<td>${edoc.id }</td>
					</tr>
					<tr>
						<td>文档名称<span style="color: red">(*)</span></td>
						<td><input type="text" name="title" value="${edoc.title }"></td>
					</tr>
					<tr>
						<td>文档摘要</td>
						<td><textarea rows="15" cols="25" name="summary">${edoc.summary }</textarea></td>
					</tr>
					
					<tr>
						<td>上传人</td>
						<td><input type="text" name="uploadUser" value="${edoc.uploadUser }"></td>
					</tr>
					<tr>
						<td>上传时间<span style="color: red">(*)</span></td>
						<td><input type="text" name="createDate" value="<fmt:formatDate value="${edoc.createDate }"/>"><span>(yyyy-MM-dd)</span></td>
					</tr>
					<tr>
						<td colspan="2"><input type="submit" value="提交"> &nbsp; <input type="button" value="返回" onclick="history.go(-1)"></td>
					</tr>
				</tbody>
			</table>
		</form>
	</div>
	
	<script type="text/javascript" src="${ctx }/static/js/jquery.js"></script>
	<script type="text/javascript">
	
	
	$("input[name = title]").blur(function () {
			var title= $("input[name = title]").val();
			if(title==""|| $.trim(title)==""){
				alert("标题不能为空");
			}
		});
		
	//日期格式验证
		
		function checkDateInput() {
			var createDate = $("input[name = createDate]").val();
			var arrTimeList = new Array();
			var isRight = false;
			arrTimeList=createDate.split("-");
			if(createDate==""|| $.trim(createDate)==""){
				alert("上传日期不能为空");
				isRight  =  true;
			}else if(arrTimeList.length != 3){
				alert("日期长度不够");
				isRight  =  true;
			}else if(arrTimeList[0]<1900 || arrTimeList[0]>2099){
				alert("输入年份范围错误");
				isRight  =  true;
			}else if(arrTimeList[1]<1 || arrTimeList[1]>12){
				alert("输入月份范围错误");
				isRight  =  true;
			}else if(arrTimeList[2]<1 || arrTimeList[2]>31){
				alert("输入日期范围错误");
				isRight  =  true;
			}else{
				for (var i = 0; i < arrTimeList.length; i++) {
					if(isNaN(arrTimeList[i])){
						alert("输入日期不是数字");
						isRight  =  true;
						break;
					}
					/* if(Math.round(arrTimeList[i]) != arrTimeList[i]){  //此方法21.0判断是整数
						alert("输入日期不是整数");  
						isRight  =  true;
						break;
					} */
					if(arrTimeList[i].indexOf(".") != -1){  
						alert("日期不能输入非整数");  
						isRight  =  true;
						break;
					} 
				}
			}
			return isRight;

		}
		
		//日期格式验证
		
		$("input[name = createDate]").blur(function () {		
			checkDateInput();
		});
		
		
		$("form").submit(function () {
			
			//提交表单标题不能为空
			var title= $("input[name = title]").val();
			if(title==""|| $.trim(title)==""){
				alert("标题不能为空");
				return false;
			} 
		
			//提交表单日期再次验证
			if(checkDateInput()){
				return false;
			}
		});
		
	</script>
	
</body>
</html>